export default class StyleSizeOperation {
  public static summation(...sizes: string[]): string {
    if (sizes.length === 0) {
      throw new Error('At least one size string should be provided.')
    }

    const totalValue = sizes.reduce((accumulator, currentSize) => {
      const value = parseFloat(currentSize)
      if (isNaN(value)) {
        throw new Error('Invalid input. All arguments should be valid size strings.')
      }
      return accumulator + value
    }, 0)

    const unit = this.getUnit(sizes[0])
    return totalValue.toString() + (unit || '')
  }
  public static multiply(value: string, multiplier: number) {
    return parseFloat(value) * multiplier + (this.getUnit(value) ?? '')
  }
  public static division(value: string, multiplier: number) {
    return this.multiply(value, 1 / multiplier)
  }
  private static getUnit(value: string): string | null {
    const unitMatch = value.match(/[a-zA-Z%]+/)
    return unitMatch ? unitMatch[0] : null
  }
}
